<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下拉菜单</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style: none;
        }
        ul.father{
            margin: 50px auto;
            width: 340px;
            height: 30px;
            background: url(./imgs/bg.jpg) no-repeat;
        }
        ul.father>li{
            float: left;
            margin-left: 10px;
            width: 100px;
            height: 30px;
            background: url(./imgs/libg.jpg) no-repeat;
            text-align: center;
            line-height: 30px;
        }
        ul.son{
            display: none;
            /* 隐藏 */
        }
        ul.son>li{
            background: url(./imgs/libg.jpg) no-repeat;
        }
    </style>
</head>
<body>
    <ul class="father">
        <li>一级标签
            <ul class="son">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
        <li>一级标签
            <ul class="son">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
        <li>一级标签
            <ul class="son">
                <li>二级标签</li>
                <li>二级标签</li>
                <li>二级标签</li>
            </ul>
        </li>
    </ul>
</body>
<script>
    var fUlLis = document.querySelectorAll('.father>li')
    var sUls = document.querySelectorAll('ul.son')

    fUlLis.forEach((item,index)=>{
        item.onmouseover = function(){
            sUls[index].style.display='block'
        }
        item.onmouseout = function(){
            sUls[index].style.display='none'
        }
    })

</script>
</html>